<template>
  <div>
    <div class="page">
      <div class="left">
        <img src="../assets/image/login_background.png" alt="" />

        <div class="left-content">
          <div>
            <img
              class="logo"
              src="http://p3-armor.byteimg.com/tos-cn-i-49unhts6dw/dfdba5317c0c20ce20e64fac803d52bc.svg~tplv-49unhts6dw-image.image"
              alt=""
              srcset=""
            />
            <p class="system-title">JH Admin</p>
            <p class="system-tips">Vue2 + Element UI</p>
          </div>
          <div class="copyright">Admin Work 2.1.0 · Made by qingqingxuan</div>
        </div>
      </div>
      <div class="right">
        <p class="weclomTitle">欢迎回来</p>
        <p class="weclomTips">登录 JH Admin 后台管理系统</p>
        <div class="loginfrom">
          <el-form ref="form" :model="form">
            <el-form-item>
              <el-input
                v-model="form.username"
                name="username"
                placeholder="请输入用户名"
                :disabled="loginLoading"
                autocomplete="on"
                autofocus
              >
                <i slot="prefix" class="el-input__icon el-icon-user"></i
              ></el-input>
            </el-form-item>
            <el-form-item style="margin-bottom: 5px">
              <el-input
                name="password"
                v-model="form.password"
                placeholder="请输入登录密码"
                show-password
                :disabled="loginLoading"
                autocomplete="on"
              >
                <i slot="prefix" class="el-input__icon el-icon-lock"></i>
              </el-input>
            </el-form-item>

            <el-form-item style="margin-bottom: 5px">
              <el-row>
                <el-col :span="6">
                  <el-checkbox
                    v-model="RememberPassword"
                    :disabled="loginLoading"
                    >记住密码</el-checkbox
                  ></el-col
                >

                <el-col :offset="13" :span="5"><span>找回密码</span></el-col>
              </el-row>
            </el-form-item>

            <el-form-item style="margin-bottom: 15px">
              <el-button
                size="100"
                type="primary"
                :loading="loginLoading"
                @click="clickLogin"
                >登录</el-button
              >
            </el-form-item>

            <el-form-item>
              <group align="center" title="第三方平台登录" />

              <div class="third-list">
                <div
                  class="third-list-li"
                  v-for="(icon, index) in third"
                  :key="index"
                  :style="{
                    background: icon.background,
                  }"
                  :title="icon.title"
                >
                  <i
                    class="overall-icon third-list-li-icon"
                    :class="icon.icon"
                    :style="{
                      color: icon.color,
                    }"
                  ></i>
                </div>
              </div>
            </el-form-item>
          </el-form>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { mapMutations, mapGetters } from "vuex";
import { saveToken } from "@/assets/overall/js/module/token";
// import { encrypt } from "@/assets/overall/js/module/encryption";
import group from "~/group/group.vue";
import API from "@/api";
// import formatModule from "@/assets/overall/js/module/format";

export default {
  components: {
    group,
  },
  computed: {
    ...mapGetters(["handleVueRouterList"], "overall"),
    // 加密用户名密码
    ciphertext() {
      // 暂时未对输入的密码任何加密，直接返回原文密码
      return this.password;
    },
  },
  data() {
    return {
      third: [
        {
          title: "微信登录",
          icon: "icon-weixin",
          fontSize: "18px",
          color: "#05873f",
          background: "#d3d3d3",
        },
        {
          title: "QQ登录",
          icon: "icon-QQ",
          fontSize: "18px",
          color: "white",
          background: "#0d80f7",
        },
        {
          title: "验证码登录",
          icon: "icon-shouji1",
          fontSize: "18px",
          color: "#ff4c4c",
          background: "#d3d3d3",
        },
      ],
      // 登录表单
      form: {
        username: "",
        password: "",
      },
      // 是否记住密码
      RememberPassword: false,
      // 登录加载框
      loginLoading: false,
      //
    };
  },

  methods: {
    ...mapMutations(
      [
        "setNavigatorMenuOriginData",
        "changeIconNavigatorCurrentId",
        "changeNavigatorCurrentId",
      ],
      "overall"
    ),
    // 切换登录/注册
    clickTag(index) {
      this.loginTypeIndex = index;
    },
    // 点击登录
    clickLogin() {
      // let password = encrypt(this.form.password);

      let password = this.form.password
      let username = this.form.username;

      if (!username) {
        this.$message.error("请输入用户名");
        return;
      }

      if (!password) {
        this.$message.error("请输入登录密码");
        return;
      }

      this.loginLoading = true;

      API.user
        .login({ type:1,username, password })
        .then((res) => {
          // 保存token
          let token = res.data.token;
          let tokenExpire = res.data.tokenExpire;
          // 存储Token
          saveToken(token, tokenExpire);
          // 用户信息
          // let userInfo = res.data.userInfo
          return API.roles.MneuList()
        })
        .then((menusList) => {
          // 设置原数据数组
          this.setNavigatorMenuOriginData(menusList);
          // 动态新增路由菜单
          this.handleVueRouterList.forEach((item) => {
            this.$router.addRoute("layout", item);
          });
          this.$message({
            message: "登录成功",
            type: "success",
          });
          this.$router.replace("/");
        })
        .catch((err) => {
          console.log(err);
          this.loginLoading = false;
          this.$message.error(err.msg);
        });
    }
  },
  mounted() {},
};
</script>

<style scoped="scoped" lang="scss">
.page {
  width: 100vw;
  height: 100vh;
  display: flex;
  flex-wrap: nowrap;
}
.left {
  width: 30%;
  height: 100%;
  position: relative;
}
.left::after {
  content: "";
  position: absolute;
  background: #0009;
  left: 0;
  top: 0;
  z-index: 10;
  width: 100%;
  height: 100%;
}

.left-content {
  position: absolute;
  height: 100%;
  width: 100%;
  left: 0;
  top: 0;
  z-index: 11;
  display: flex;
  box-sizing: border-box;
  align-items: center;
  padding: 18px 0px;
  flex-direction: column;
  justify-content: space-between;
}

.left-content .logo {
  width: 110px;
  height: 110px;
}
.left-content .system-tips,
.left-content .system-title {
  color: white;
  font-weight: bold;
}
.left-content .system-title {
  font-size: 28px;
}
.left-content .system-tips {
  margin-top: 20px;
  font-size: 15px;
}
.left-content .copyright {
  font-size: 15px;
  color: white;
}

.right {
  flex: 1;
  height: 100vh;
  display: flex;
  background: white;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

img {
  width: 100%;
  height: 100%;
}

.from {
  flex: 1;
  height: 100vh;
}
.weclomTitle {
  text-align: center;
  font-size: 23px;
  margin-bottom: 15px;
  width: 80%;
  user-select: none;
}
.weclomTips {
  font-size: 18px;
  text-align: center;
  color: gray;
  user-select: none;
}
.loginfrom {
  width: 280px;
  margin-top: 25px;
}
.loginfrom /deep/ .el-button {
  width: 100%;
}
.third {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;

  &-list {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-top: 5px;
    &-li {
      width: 34px;
      height: 34px;
      border-radius: 50%;
      background: gray;
      margin-right: 15px;
      text-align: center;
      line-height: 34px;
      &:last-child {
        margin-right: 0px;
      }

      &-icon {
        font-size: 20px;
      }

      &-wechat {
        font-size: 18px;
      }
    }
  }
}
.login-box {
  width: 440px;
  background: #000;
  border-radius: 16px;
  background: #fff;
  flex-direction: column;
}

/* Tag标签 */
.tag {
  margin-top: 15px;
  height: 50px;
  line-height: 50px;
  padding-left: 30px;
  position: relative;
  color: #c3c3c3;
  font-size: 18px;
  letter-spacing: 4px;
}
/* 标签焦点样式 */
.tag-slider {
  width: 43px;
  height: 4px;
  border-radius: 10px;
  background-color: #42b983;
  position: absolute;
  bottom: 0px;
  display: none;
  left: 0px;
  transition: all 0.3s linear;
}
.tag span {
  margin-right: 15px;
  text-align: center;
}
/* Tag 选中样式 */
.tag-tips-checked {
  color: #000000;
}

.login {
  margin: 0 auto;
  width: 300px;
  height: 190px;
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  align-items: center;
}
.register {
  margin: 0 auto;
  width: 300px;
  flex-direction: column;
  height: 180px;
}
.login,
.register {
  margin-top: 15px;
}

.input {
  width: 100%;
  display: block;
  outline: none;
  border-radius: 40px;
  text-indent: 20px;
  border: none;
  background-color: #e3e3e366;
  font-size: 18px;
  height: 55px;
}

.loginBtn {
  width: 60%;
  height: 50px;
  margin: 0 auto;
  border-radius: 60px;
  background-color: #42b983;
  color: #fff;
  line-height: 50px;
  letter-spacing: 4px;
  margin-top: 15px;
  cursor: default;
  text-align: center;
}
.loginBtn:hover {
  background-color: cornflowerblue;
}
.loginBtn:active {
  background-color: #42b983;
}
.agreement {
  text-align: center;
  margin: 15px 0px;
}
.grey,
.view-text {
  margin-left: 8px;
  font-size: 10px;
  vertical-align: middle;
}

.view-text {
  text-decoration: underline;
}

.checked-false {
  display: inline-block;
  width: 10px;
  height: 10px;
  vertical-align: middle;
  border-radius: 50%;
  background-color: #eee;
  border: 1px solid #c3c3c324;
}

.checked-true {
  background-color: #6495ed;
  border-color: #6495ed;
}

.grey {
  user-select: none;
  cursor: default;
  color: #2c3e50;
  margin-right: 8px;
}
</style>
